import SocketServer 

HOST = '' 
PORT = 6000 
ADDR = (HOST, PORT) 
class MyRequestHandler(SocketServer.BaseRequestHandler): 
    def handle(self): 
        print '...connected from:', self.client_address

        while(True):
            try:
                self.data = self.request.recv(1024)
            except IOError, e:
                print  e
                print 'client {} closed connection'.format(self.client_address)
                break
            else:
                print '{a1}:{a2} wrote:'.format(a1=self.client_address[0], a2=self.client_address[1])
                print self.data
                self.request.sendall(self.data.upper())

tcpServ = SocketServer.ThreadingTCPServer(ADDR, MyRequestHandler) 
print 'waiting for connection...'
tcpServ.serve_forever()
